//
//  MyStockStockChildListController.m
//  Stock
//
//  Created by blacksun on 11-6-26.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "MyStockStockChildListController.h"
#import "StockListController.h"

@implementation MyStockStockChildListController
@synthesize stockId;
@synthesize parentController;
@synthesize myStockNewsService;

#pragma mark -Service Delegate
-(void)requestFinishedWithResult:(id)aResult andUserinfo:(NSDictionary *)aUserinfo{
    [super requestFinishedWithResult:aResult andUserinfo:aUserinfo];
    self.stockNewses = aResult;
    [parentController childViewDidUpdated:self.tableView.rowHeight*[stockNewses count]];
    [self.tableView reloadData];
    self.tableView.tableFooterView = nil;
}
-(void)requestFinishedwithError:(NSError *)aError andUserinfo:(NSDictionary *)aUserinfo{
    
}

-(void)queryStocknewses{
    //NSString *queryUrl = [[NSString alloc] initWithFormat:@"%@report/list?sid=%@&start=%d&id=%@",kHostName,@"CR",35,@"sh600887"];
    NSString *queryUrl = [[NSString alloc] initWithFormat:@"%@report/list?sid=%@&start=%d&id=%@",kHostName,sectionId,currentIndex-1,stockId];
    //NSLog(@"%@",queryUrl);
    [myStockNewsService queryStockNewsWithUrl:queryUrl ifNotExistInDBWithSectionId:sectionId stockId:stockId andSectionIndex:currentIndex];
    [queryUrl release];
}

-(void)viewDidLoad{
    [super viewDidLoad];
    self.tableView.bounces = NO;
    self.tableView.scrollEnabled = NO;
    currentIndex = sectionIndex + 1;
    self.myStockNewsService = [[[MyStockNewsService alloc] initWithDelegate:self] autorelease];
    [self performSelector:@selector(queryStocknewses) withObject:nil afterDelay:0.2];
}

-(void)viewDidUnload{
    [super viewDidUnload];
    [myStockNewsService cancleAllRequest];
    self.myStockNewsService = nil;
}
-(void)dealloc{
    [self.myStockNewsService cancleAllRequest];
    self.myStockNewsService = nil;
    self.stockId = nil;
    [super dealloc];
}

@end
